package cc.md888.app.application.feedback;

import cc.md888.app.domain.entity.Feedback;
import cc.md888.app.infr.dao.FeedbackDao;
import cc.md888.app.model.feedback.ContactInfoVO;
import cc.md888.app.model.feedback.CreateFeedbackCmd;
import cc.md888.app.model.feedback.FeedbackQuery;
import cc.md888.app.model.feedback.FeedbackVO;
import cc.md888.dto.PageQuery;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 反馈
 */
@Component
public class FeedbackService {


    @Autowired
    private FeedbackDao feedbackDao;



    public void create(CreateFeedbackCmd cmd){
        Feedback feedback = new Feedback();
        feedback.setUserId(0L);
        feedback.setContact(cmd.getContact());
        feedback.setContent(cmd.getContent());
        feedbackDao.save(feedback);
    }


    /**
     * 反馈列表
     * @param page
     * @return
     */
    public IPage<FeedbackVO> listPage(PageQuery<FeedbackQuery> page){
        return feedbackDao.page(
                new Page<>(page.getPageIndex(), page.getPageSize()),
                Wrappers.<Feedback>query().orderByDesc("id")
        ).convert(this::convert);
    }


    /**
     * 联系方式
     * @return
     */
    public List<ContactInfoVO> getContactInfo(){
        ContactInfoVO tg = new ContactInfoVO();
        tg.setTitle("TG客服");
        tg.setSubtitle("t.me/maodou186");
        tg.setLink("https://t.me/maodou0001");
        tg.setImgUrl("https://blog.md888.cc/posts/sale-fb-account/images/maodou0001.png");

        ContactInfoVO channel = new ContactInfoVO();
        channel.setTitle("TG频道");
        channel.setSubtitle("md888.cc");
        channel.setLink("https://t.me/maodou186");
        channel.setImgUrl("https://blog.md888.cc/posts/sale-fb-account/images/maodou186.png");

        ContactInfoVO website = new ContactInfoVO();
        website.setTitle("官网");
        website.setSubtitle("md888.cc");
        website.setLink("https://md888.cc");
        website.setImgUrl("https://blog.md888.cc/posts/sale-fb-account/images/md888.cc.png");

        return Lists.newArrayList(
                tg, channel, website
        );
    }


    public FeedbackVO convert(Feedback feedback){
        FeedbackVO feedbackVO = new FeedbackVO();
        BeanUtils.copyProperties(feedback, feedbackVO);
        return feedbackVO;
    }

}
